package com.example.yue.appclent;

/**
 * @author Yue
 * @date 2017/8/14 15:31
 */
public class StringRegex {
    /**
     * ip4校验
     * @param content
     * @return
     */
    public static boolean isIp4(String content) {
        String[] splits = content.split("\\.");
        if (splits.length == 4) {
            for (int i = 0; i < splits.length; i++) {
                String item = splits[i];
                if (isNumber(item)) {
                    int num = Integer.parseInt(item);
                    if (num > 255) {
                        return false;
                    }
                } else {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    /**
     * 无符号数字
     *
     * @param content
     * @return
     */
    public static boolean isNumber(String content) {
        if (content == null){
            return false;
        }
        return content.matches("[0-9]+");
    }
}
